package com.yunpai.SingleMolde;

/**
 * 饿汉式(静态常量)
 */
public class SingleHungryType01 {


    /**
     * 构造器私有化防止new
     */
    private SingleHungryType01() {

    }

    /**
     * 类的内部创建对象
     * 静态常量
     */

    private static SingleHungryType01 singleHungry = new SingleHungryType01();

    /**
     * 提供一个公开的public方法,可以返回singleHungry对象
     */

    public static SingleHungryType01 getInstance() {
        return singleHungry;
    }

}

class Main1 {

    /**
     * 测试
     */
    public static void main(String[] args) {
        SingleHungryType01 singleHungry = SingleHungryType01.getInstance();
        SingleHungryType01 singleHungry1 = SingleHungryType01.getInstance();
        System.out.println(singleHungry == singleHungry1);
        System.out.println("singleHungry.hashCode=" + singleHungry.hashCode());
        System.out.println("singleHungry1.hashCode=" + singleHungry1.hashCode());
        //结果相同,说明是同一个对象实列
    }
}
